package com.yuhs.zixing.pay.util;

/**
 * @className: WorkerId
 * @description: WorkerId
 * @author: xiaofei
 * @create: 2020年01月20日
 */
final class WorkerId {

    public static long getWorkerId() {
        String mac = getMAC();
        long value = Long.parseLong(mac.toString(), 10);
        return value % 31;
    }

    /**
     * 获取MAC地址并截取
     *
     * @return
     */
    private static String getMAC() {
        String mac = MAC.getMAC();
        String[] splits = mac.split(":");
        StringBuilder tostr = new StringBuilder();
        for (String split : splits) {
            tostr.append(Integer.parseInt(split, 16));
        }
        return tostr.toString();
    }

    private WorkerId() {
        throw new AssertionError("Uninstantiable class.");
    }
}
